<template>
  <div class="container">
    <!-- 标题 -->
    <div class="settitle">
      <div class="setimg" @click="$router.back()">
        <img src="../assets/imgs/iconse/左箭头.png" alt="" />
      </div>
      <div class="text"><h2>账号设置</h2></div>
    </div>
    
    <div class="setbox">
      <div class="item">
        <div class="itemleft">
          <span>微信</span>
        </div>
        <div class="itemrigth">
          <span>未开放</span>
        </div>
      </div>
      <div class="item">
        <div class="itemleft">
          <span>QQ</span>
        </div>
        <div class="itemrigth">
          <span>未开放</span>
        </div>
      </div>
      <div class="item">
        <div class="itemleft">
          <span>手机号</span>
        </div>
        <div class="itemrigth" @click="show = false">
          <span class="nums" v-if="show">{{ phones }}</span>
          <input
            type="text"
            v-if="!show"
            @keydown.enter="add"
            v-model="val"
            @keydown.esc="esc"
          />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      phones: "",
      show: true,
      val: null,
    };
  },
  methods: {
    add() {
      let reg =
        /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;
      console.log(this.val);
      if (!reg.test(this.val)) {
        //不正确处理
        this.$toast("请输入正确手机号码");
        this.val = "";
        return;
      } else {
        let frs = this.val.toString().split("");
        let aa = frs[0] + frs[1] + frs[2];
        let bb = frs[9] + frs[10];
        let cc = aa + "******" + bb;
        window.localStorage.setItem("phone", cc);
        this.phones=cc;
        this.val = "";
        this.show = true;
      }
    },
    esc() {
      this.val = "";
      this.show = true;
    },
  },
  created() {
    this.phones = localStorage.getItem("phone");
  },
};
</script>

<style lang="scss" scoped>
input {
  font-size: 20px;
  border-radius: 10px;
  text-indent: 1em;
  border: 1px solid #ccc;
  color: #333;
}
.settitle {
  height: 60px;
  display: flex;
  align-items: center;
  background-color: #fff;
  box-shadow: 0px 0px 0px 1px rgba($color: #cccc, $alpha: 0.4);
  .setimg {
    height: 18px;
    position: absolute;
    left: 15px;
    img {
      height: 100%;
      display: block;
    }
  }
  .text {
    margin: 0 auto;
  }
}
.setbox {
  box-sizing: border-box;
  padding: 10px 20px;
  background-color: #fff;
  margin-top: 20px;
  .item {
    display: flex;
    position: relative;
    height: 45px;
    line-height: 45px;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 10px;
    padding-top: 10px;
    font-size: 20px;
    border-bottom: 1px solid rgba($color: #cccc, $alpha: 0.2);
    &:nth-last-child(1) {
      padding-bottom: 0px;
      border-bottom: 0px;
    }
    &:nth-child(1) {
      padding-top: 0px;
    }
    .itemrigth {
      span {
        font-size: 16px;
      }
      .nums {
        margin-right: 35px;
        position: relative;
        &::after {
          content: "";
          display: block;
          position: absolute;
          width: 20px;
          height: 20px;
          top: 0px;
          bottom: 0px;
          right: -35px;
          margin: auto 0;
          // background-color: red;
          background: url(../assets/imgs/右箭头.png) no-repeat center center;
          background-size: 70%;
        }
      }
    }
  }
}
</style>